package com.graduation.smartparkingplatform.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.graduation.smartparkingplatform.Dao.RegionMapper;
import com.graduation.smartparkingplatform.Pojo.Region;
import com.graduation.smartparkingplatform.Pojo.Space;
import com.graduation.smartparkingplatform.Service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements RegionService {

  @Autowired RegionMapper regionMapper;

  // 获取Region列表（分页）
  @Override
  public PageInfo<Region> getRegionList(Integer page, Integer count) {
    PageHelper.startPage(page, count);

    List<Region> regionList = regionMapper.getRegionList();

    PageInfo<Region> pageInfo = new PageInfo<>(regionList);

    return pageInfo;
  }

  // 模糊搜索User（分页）
  @Override
  public PageInfo<Space> spaceByRegion(Integer page, Integer count, Integer regionId) {
    PageHelper.startPage(page, count);

    List<Space> spaceByRegionList = regionMapper.spaceByRegion(regionId);

    PageInfo<Space> pageInfo = new PageInfo<>(spaceByRegionList);

    return pageInfo;
  }

  // 模糊搜索User（分页）
  @Override
  public PageInfo<Region> searchRegion(
      Integer page, Integer count, String regionName, String regionType) {
    PageHelper.startPage(page, count);

    List<Region> searchList = regionMapper.searchRegion(regionName, regionType);

    PageInfo<Region> pageInfo = new PageInfo<>(searchList);

    return pageInfo;
  }

  // 添加停车场区域
  public Boolean addRegion(Region region) {
    Integer orgId = region.getOrg_id();
    String regName = region.getReg_name();
    String regType = region.getReg_type();
    Integer regSpaceCount = region.getReg_space_count();
    Integer regSpaceRecount = region.getReg_space_recount();
    String regRemarks = region.getReg_remarks();

    return regionMapper.addRegion(
        orgId, regName, regType, regSpaceCount, regSpaceRecount, regRemarks);
  }

  // 修改区域信息
  @Override
  public Boolean changeInfo(Region region) {
    Integer regId = region.getReg_id();
    Integer orgId = region.getOrg_id();
    String regName = region.getReg_name();
    String regType = region.getReg_type();
    Integer regSpaceCount = region.getReg_space_count();
    Integer regSpaceRecount = region.getReg_space_recount();
    String regRemarks = region.getReg_remarks();

    return regionMapper.changeInfo(
        regId, orgId, regName, regType, regSpaceCount, regSpaceRecount, regRemarks);
  }

  // 删除停车场区域
  @Override
  public Boolean deleteRegion(Integer regionId) {
    return regionMapper.deleteRegion(regionId);
  }
}
